function plot_specw(s,P,time,O,coeffs,opts);

pls=3:length(s);

figure(1); clf; 

subplot(511); cla; hold on;
plot(time,O,'k','linewidth',1); axis tight;
if opts.yrev,
    set(gca,'ydir','reverse'); 
end;
font(gca,14); 
h=xlabel('year'); font(h,14);
h=ylabel(opts.ylab); font(h,14);
set(gca,'xaxisloc','top');
h4=axis; dhx=diff(h4(1:2)); dhy=diff(h4(3:4));
h=text(h4(1)+dhx*0.01,h4(4)-dhy*0.03,'(a)'); font(h,14);

subplot(5,3,[4 5 7 8]); cla; hold on;
for ct=1:length(opts.xlines);
    xline(opts.xlines(ct),'k--','linewidth',1);
end;
%un-prewhitened spectral estimate
plot(s(pls),P.initial(pls),'k','linewidth',1); 
plot(s(pls),P.pre_fit(pls),'r','linewi',1); 
plot(s(pls),P.pre_fit(pls)+coeffs.chi95,'r--','linewi',1); 
if opts.xlog, set(gca,'xscale','log'); end;
axis tight;
%h=xlabel('frequency (1/yr)'); font(h,14); 
h=ylabel({'power spectral density' '(log_{10} units^2/ds)'}); font(h,14); 
font(gca,14);
h4=axis; dhx=diff(h4(1:2)); dhy=diff(h4(3:4));
h=text(h4(1)*1.1,h4(3)+dhy*0.1,'(b)'); font(h,14);

subplot(5,3,[6 9]); cla; hold on;
[F,xi]=ksdensity(P.initial(pls)-P.pre_fit(pls));
plot(xi,F,'k','linewidth',1);
ypdf=pdflogchi2(xi+log(coeffs.dof),coeffs.dof);
plot(xi,ypdf,'r','linewidth',1);
%h=xlabel('residuals'); font(h,14); 
h=ylabel('distribution'); font(h,14); 
font(gca,14);
h4=axis; dhx=diff(h4(1:2)); dhy=diff(h4(3:4));
h=text(h4(1)+dhx*0.01,h4(4)-dhy*0.03,'(c)'); font(h,14);

subplot(5,3,[10 11 13 14]); cla; hold on;
for ct=1:length(opts.xlines);
    xline(opts.xlines(ct),'k--','linewidth',1);
end;
plot(s(pls),P.prewhiten(pls),'k','linewidth',1); 
plot(s(pls),P.post_fit(pls),'r','linewi',1); 
plot(s(pls),P.ci95(pls),'r--','linewi',1); 
plot(s(pls),P.ci95b(pls),'m--','linewi',1); 
if opts.xlog, set(gca,'xscale','log'); end;
axis tight;
h=xlabel('frequency (1/yr)'); font(h,14); 
h=ylabel({'whitened density' '(log_{10} units^2/ds)'}); font(h,14); font(gca,14);
h4=axis; dhx=diff(h4(1:2)); dhy=diff(h4(3:4));
h=text(h4(1)*1.1,h4(4)-dhy*0.05,'(d)'); font(h,14);

subplot(5,3,[12 15]); cla; hold on;
[F,xi]=ksdensity(P.prewhiten(pls)-P.post_fit(pls));
plot(xi,F,'k','linewidth',1);
ypdf=pdflogchi2(xi+log(coeffs.dof),coeffs.dof);
plot(xi,ypdf,'r','linewidth',1);
h=xlabel('residuals'); font(h,14); 
h=ylabel('distribution'); font(h,14); 
font(gca,14);
h4=axis; dhx=diff(h4(1:2)); dhy=diff(h4(3:4));
h=text(h4(1)+dhx*0.01,h4(4)-dhy*0.03,'(e)'); font(h,14);

[mean(P.initial-P.pre_fit) var(P.initial-P.pre_fit) coeffs.Vexp mean(P.initial>(P.pre_fit+coeffs.chi95))],
[mean(P.prewhiten-P.post_fit) var(P.prewhiten-P.post_fit) coeffs.Vexp mean(P.prewhiten>P.ci95)],
